package com.duyi.controller;

import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class MyExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");

        if (ex instanceof MyException) {
            mv.addObject("data", "MyException 信息");
        } else {
            mv.addObject("data", "其他信息");
        }

        return mv;
    }
}
